/***************************/
//@Author: Adrian "yEnS" Mato Gondelle & Ivan Guardado Castro
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

$(document).ready(function(){
	//global vars
	var form = $("#customForm");
	var budget = $("#budget");
	var budgetInfo = $("#budgetInfo");
	var event = $("#event");
	var eventInfo = $("#eventInfo");
	
	//On blur
	budget.blur(validateBudget);
	event.blur(validateEmail);
	//On key press
	budget.keyup(validateBudget);
	//On Submitting
	form.submit(function(){
		if(validateBudget() & validateEmail())
			return true
		else
			return false;
	});
	
	//validation functions
	function validateEvent(){
		//if it's valid event
		event.removeClass("error");
		eventInfo.text("Valid event please, you will need it to log in!");
		eventInfo.removeClass("error");
		return true;
	}
	function validateBudget(){
		//if it's NOT valid
		var a = $("#budget").val();
		var filter = /[0-9]/;
		if(budget.val().length == 0){
			budget.removeClass("error");
			budgetInfo.text("What's your Budget?");
			budgetInfo.removeClass("error");
			return true;
		}
		else if(!filter.test(a)){
			budget.addClass("error");
			budgetInfo.text("Valid Budget please, you have to enter the correct budget");
			budgetInfo.addClass("error");
			return false;
		}
		//if it's valid
		else{
			budget.removeClass("error");
			budgetInfo.text("What's your Budget?");
			budgetInfo.removeClass("error");
			return true;
		}
	}
});